﻿@Html.DevExpress().GridView(
    settings => {
        settings.Name = "grid";
        settings.CallbackRouteValues = new { Action = "AdvancedSelectionPartial", Controller = "Selection" };
        settings.Width = Unit.Percentage(100);
        settings.Styles.TitlePanel.CssClass = "titleContainer";
        
        settings.KeyFieldName="CustomerID";
        settings.CommandColumn.Visible = true;
        settings.CommandColumn.ShowSelectCheckbox = true;
        settings.CommandColumn.ShowClearFilterButton = true;
        settings.CommandColumn.SelectAllCheckboxMode = GridViewSelectionDemoHelper.SelectAllButtonMode;
        settings.Columns.Add("ContactName");
        settings.Columns.Add("CompanyName");
        settings.Columns.Add("City");
        settings.Columns.Add("Region");
        settings.Columns.Add("Country");
        
        settings.Settings.ShowTitlePanel = true;
        settings.Settings.ShowFilterRow = true;
        settings.SettingsBehavior.AllowDragDrop = false;
        settings.ClientSideEvents.Init = "OnGridViewInit";
        settings.ClientSideEvents.SelectionChanged = "OnGridViewSelectionChanged";
        settings.ClientSideEvents.EndCallback = "OnGridViewEndCallback";
        settings.CustomJSProperties = (s, e) => {
            MVCxGridView grid = s as MVCxGridView;
            if(grid != null)
                e.Properties["cpVisibleRowCount"] = grid.VisibleRowCount;
        };
        
        settings.SetTitlePanelTemplateContent(c => {
            ViewContext.Writer.Write(@"<span id=""lblInfo""></span>");
            if(settings.CommandColumn.SelectAllCheckboxMode != GridViewSelectAllCheckBoxMode.AllPages) {
                ViewContext.Writer.Write(
                    @"<a id=""lnkSelectAllRows"" style=""cursor: pointer;"">Select all rows.</a>
                      <a id=""lnkClearSelection"" style=""cursor: pointer;"">Clear selection.</a>"
                );
            }
        });
    }).Bind(Model).GetHtml()